﻿using System;
using System.Linq;
using Coffee_Restaurant.Database;

namespace Coffee_Restaurant.DAL
{
    public class DinnerMenuCategoryDa
    {
        public static int Delete(int id)
        {
            try
            {
                using (var db = new DatabaseEntities())
                {
                    var model = db.DinnerMenuCategories.Find(id);
                    if (model != null)
                    {
                        db.DinnerMenuCategories.Remove(model);
                        return db.SaveChanges();
                    }
                }
            }
            catch (Exception)
            {

                return 0;
            }
            return 0;
        }

        public static int DeleteByName(string name)
        {
            try
            {
                using (var db = new DatabaseEntities())
                {
                    var model = db.DinnerMenuCategories.FirstOrDefault(x => x.Name == name);
                    if (model != null)
                    {
                        db.DinnerMenuCategories.Remove(model);
                        return db.SaveChanges();
                    }
                }
            }
            catch (Exception)
            {

                return 0;
            }
            return 0;
        }


        public static int CountRef(string groupname)
        {
            using (var db = new DatabaseEntities())
            {
                return db.DinnerMenus.Count(x => x.GroupName == groupname);
            }
        }
    }
}
